
<?php
	
	include('config.php');
	
	
	// Build SQL Query  
	
	$userid = $_SESSION['userid'];
	
	$query = 'SELECT tbartifacts.Id, tbartifacts.Title, tbartifacts.Text, tbartifacts_type.Name, 
	          tbusers.Name AS Author
			  FROM tbartifacts, tbartifacts_type, tbusers 
			  WHERE tbusers.Id = ' . $userid . ' AND tbusers.Id = tbartifacts.Author AND tbartifacts_type.Id = tbartifacts.Type  ';
	
		
	mysql_query("set names utf8");
	 
	$numresults = mysql_query($query);
	 
	if (!$numresults) 
	{
		die('Invalid query: ' . mysql_error());
	}
	 
	$numrows = mysql_num_rows($numresults);
	
	// Writing the table with the query results. 
	echo ("<tbody>");
		 
	while ($row = mysql_fetch_assoc($numresults)) 
	{   		
		echo ("<tr>");	
		echo ("<td> <a href='download.php?id=" . $row["Id"] .   " '> " . $row["Title"] . " </a> </td>");
		echo ("<td>" . $row["Text"] . "</td>");
		echo ("<td>" . $row["Name"] . "</td>");
		echo ("<td>" . $row["Author"] . "</td>");
		echo ("</tr>");	
			
	}// while
	
	echo ("</tbody>");
	
	// Table Foot 
	echo ("<tfoot>");
		echo ("<tr>");
			echo ("<td colspan='4'>" . $numrows . " resultados encontrados</td>");
		echo ("</tr>");
	echo ("</tfoot>");
	
	
	// If we have no results	
	if ($numrows == 0)
	{
		//echo "<h4>Results</h4>";
		//echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";
	}//if
	
	  
?>